import { Component, OnInit } from '@angular/core';
import {Carousel} from '../../model/Carousel';
import {CarouselService} from '../../services/carousel.service';
import {ConfigService} from '../../services/config.service';
import {ToastService} from '../../services/toast.service';

@Component({
  selector: 'app-carousel',
  templateUrl: './carousel.component.html',
  styleUrls: ['./carousel.component.css']
})
export class CarouselComponent implements OnInit {
  images:Array<string>;
  cl:Array<Carousel>;
  constructor(private carouselservice:CarouselService
  ,public config:ConfigService
  ,private toastservice:ToastService) {
    // this.images=[
    //     //   "http://localhost:8080/public/img/c1.jpg",
    //     //   "http://localhost:8080/public/img/c2.jpg",
    //     //   "http://localhost:8080/public/img/c3.jpg",
    //     //   "http://localhost:8080/public/img/c4.jpg",
    //     //   "http://localhost:8080/public/img/c5.jpg",
    //     //   "http://localhost:8080/public/img/c6.jpg"
    //     // ]
    this.cl=new Array();
    // for(let i=1;i<6;i++){
    //   let c=new Carousel();
    //   c.url='http://localhost:4200/newsdetail;newsid=d4856589-c3b5-421d-862a-9363dc9a83bf';
    //   c.title="标题"+i;
    //   c.pic="http://localhost:8080/public/img/c"+i+".jpg";
    //   this.cl.push(c);
    // }
     this.loadCarousel();
  }

  ngOnInit(): void {
  }

  loadCarousel(){
    this.carouselservice.getCarouselList()
      .then((data:any)=>{
        if(data.msg=='ok'){
          this.cl=new Array();
          this.cl=data.list;
        }
        else if(data.msg=='empty'){
          this.cl=new Array();
          this.toastservice.showWarning('还没有上传图片');
        }
        else {
          this.toastservice.showError('与服务端通讯异常');
        }


      })
  }

}
